function findResources() {
  const resources = {
    video: [],
    image: [],
    audio: []
  };

  // 收集视频资源
  document.querySelectorAll('video, source[type^="video"]').forEach(video => {
    const src = video.src || video.currentSrc;
    if (src) resources.video.push(src);
  });

  // 收集图片资源
  document.querySelectorAll('img').forEach(img => {
    if (img.src) resources.image.push(img.src);
  });

  // 收集音频资源
  document.querySelectorAll('audio, source[type^="audio"]').forEach(audio => {
    const src = audio.src || audio.currentSrc;
    if (src) resources.audio.push(src);
  });

  return resources;
}

// 监听来自popup的消息
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  if (request.action === 'getResources') {
    sendResponse(findResources());
  }
});